package com.cloudkinto.controller.workOrder;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.workOrder.WorkOrderQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.workOrder.WorkOrderService;
import com.cloudkinto.vo.workOrder.WorkOrderDetail;
import com.cloudkinto.vo.workOrder.WorkOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 工单 前端控制器
 * </p>
 *
 * @author long
 * @since 2025-01-07
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "wms工单模块")
@RequestMapping("/api/admin/wms/workOrder")
public class WorkOrderWmsController extends BaseController {
    private final WorkOrderService workOrderService;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "工单根据id查看详情", notes = "工单根据id查看详情")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WorkOrderDetail.class))
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", workOrderService.detail(id));
    }

    @UserSessionRequired
    @PutMapping("/refuse/{id}")
    @ApiOperation(value = "拒绝", notes = "拒绝")
    public SingleResult refuse(@PathVariable("id") Long id) {
        return SingleResult.success("拒绝成功", workOrderService.refuse(id, getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PutMapping("/approvePass/{id}")
    @ApiOperation(value = "审核通过", notes = "审核通过")
    public SingleResult approvePass(@PathVariable("id") Long id) {
        return SingleResult.success("审核通过", workOrderService.approvePass(id, getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PutMapping("/solveFinish/{id}")
    @ApiOperation(value = "处理完成", notes = "处理完成")
    public SingleResult solveFinish(@PathVariable("id") Long id) {
        return SingleResult.success("处理完成", workOrderService.solveFinish(id, getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PutMapping("/settlementWorkOrder/{id}")
    @ApiOperation(value = "结算工单", notes = "结算工单")
    public SingleResult settlementWorkOrder(@PathVariable("id") Long id) {
        return SingleResult.success("结算完成", workOrderService.settlementWorkOrder(id, getTenantId(), getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "工单查询初始化", notes = "工单查询初始化")
    public SingleResult pageInit() {
        return workOrderService.pageInit(getCurrentUserId(), getTenantId(), getCompanyId(), "wms");
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "工单查询（分页）", notes = "工单查询（分页）")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WorkOrderVo.class))
    public PageResult listPage(@RequestBody @Validated WorkOrderQueryBo bo) {
        bo.setWhId(getWarehouseId());
        return workOrderService.getListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/listPageStatusSta")
    @ApiOperation(value = "工单查询分页状态统计", notes = "工单查询分页状态统计")
    public SingleResult listPageStatusSta(@RequestBody @Validated WorkOrderQueryBo bo) {
        bo.setWhId(getWarehouseId());
        bo.setStatus(null);
        return workOrderService.listPageStatusSta(bo);
    }
}

